using System.Collections;
using UnityEngine;

public class CharacterInformation : MonoBehaviour
{
	public bool isAlive;

	public bool isGrounded;

	public float sinceGrounded;

	public float sinceWall = 1f;

	public float isFallen;

	public float shortestDistanceFromHeadToGround;

	public float sinceJumped;

	public bool freeze;

	public int jumpTick;

	private Vector3 landPosition;

	public Vector3 wallNormal;

	private PartCheckCollision[] groundCheckers;

	public Transform headTransform;

	public Rigidbody mainRig;

	public Rigidbody holderRig;

	private Rigidbody[] rigidbodies;

	[SerializeField]
	private CharacterRenderer characterRenderer;

	public TweenPosition tweener;

	private Coroutine cImmo;

	public bool isDemo;

	[Header("Stats")]
	public int kills;

	public int headShots;

	public int waves;

	private AudioSource source;

	public AudioClip gethit;

	public AudioClip jump;

	public AudioClip pickup;

	public AudioClip swing;

	public AudioClip die;

	public MenuVisualEffectController menuVisual;

	public void PlayGetHit()
	{
		if ((!(menuVisual != null) || menuVisual.CanPlaySound()) && PersistenData.Sound)
		{
			source.PlayOneShot(gethit);
		}
	}

	public void PlayJump()
	{
		if ((!(menuVisual != null) || menuVisual.CanPlaySound()) && PersistenData.Sound)
		{
			source.PlayOneShot(jump);
		}
	}

	public void PlayPickup()
	{
		if ((!(menuVisual != null) || menuVisual.CanPlaySound()) && PersistenData.Sound)
		{
			source.PlayOneShot(pickup);
		}
	}

	public void PlaySwing()
	{
		if ((!(menuVisual != null) || menuVisual.CanPlaySound()) && PersistenData.Sound)
		{
			source.PlayOneShot(swing);
		}
	}

	public void PlayDie()
	{
		if ((!(menuVisual != null) || menuVisual.CanPlaySound()) && PersistenData.Sound)
		{
			source.PlayOneShot(die);
		}
	}

	private void Awake()
	{
		source = base.gameObject.AddComponent<AudioSource>();
		source.playOnAwake = false;
		source.loop = false;
		rigidbodies = GetComponentsInChildren<Rigidbody>();
	}

	private void Start()
	{
		groundCheckers = GetComponentsInChildren<PartCheckCollision>();
		Rigidbody[] array = rigidbodies;
		foreach (Rigidbody rigidbody in array)
		{
			rigidbody.maxAngularVelocity = 20f;
		}
	}

	private void Update()
	{
		if (!isAlive)
		{
			isFallen = -10f;
		}
		CheckIfGrounded();
		isFallen += Time.deltaTime;
		sinceJumped += Time.deltaTime;
		sinceWall += Time.deltaTime;
		if (!isGrounded)
		{
			sinceGrounded += Time.deltaTime;
			return;
		}
		if (sinceGrounded > 0.4f)
		{
		}
		sinceGrounded = 0f;
	}

	private void CheckIfGrounded()
	{
		int num = groundCheckers.Length;
		isGrounded = false;
		for (int i = 0; i < num; i++)
		{
			if (groundCheckers[i].isGrounded)
			{
				float num2 = Vector3.Distance(headTransform.position, groundCheckers[i].collisionPosition);
				if (num2 < shortestDistanceFromHeadToGround || !isGrounded)
				{
					shortestDistanceFromHeadToGround = num2;
					landPosition = groundCheckers[i].collisionPosition;
				}
				if (sinceJumped > 0.2f)
				{
					isGrounded = true;
				}
			}
		}
	}

	public void SetColor(Color c)
	{
		characterRenderer.SetColor(c, init: true);
		GetComponent<CharacterParticles>().SetParticleColors(c);
	}

	public void Heal()
	{
		GetComponent<CharacterParticles>().PlayHealthEffect(mainRig.position);
		GetComponent<CharacterHealth>().HealStickman();
	}

	public void Immortal(float duration)
	{
		if (cImmo != null)
		{
			StopCoroutine(cImmo);
		}
		cImmo = StartCoroutine(coroImmortal(duration));
	}

	private IEnumerator coroImmortal(float duration)
	{
		GetComponent<CharacterParticles>().PlayImmoEffect();
		GetComponent<CharacterHealth>().CanTakeDamage = false;
		yield return new WaitForSeconds(duration);
		GetComponent<CharacterParticles>().StopImmoEffect();
		GetComponent<CharacterHealth>().CanTakeDamage = true;
	}

	public void Freeze(bool enableCollider = false)
	{
		freeze = true;
		Rigidbody[] array = rigidbodies;
		foreach (Rigidbody rigidbody in array)
		{
			if (rigidbody != null)
			{
				rigidbody.isKinematic = true;
				rigidbody.GetComponent<Collider>().enabled = enableCollider;
			}
		}
	}

	public void DeFreeze()
	{
		freeze = false;
		Rigidbody[] array = rigidbodies;
		foreach (Rigidbody rigidbody in array)
		{
			if (rigidbody != null)
			{
				rigidbody.isKinematic = false;
				rigidbody.GetComponent<Collider>().enabled = true;
			}
		}
	}

	public void ShowHit()
	{
		characterRenderer.FlashColorOnHit();
	}
}
